package lormi.meipin.common;


import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;

import lormi.meipin.exception.LMException;


import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;

/**
 * 七牛上传
 * */
public class LMQiNiuAPI {
	
	
	private static final String access = "Umel9l7SRELt3Cq6nB_KxW-Crj4LJwW735loAIKY";
	private static final String secret_key = "pGqfBRkFzcArXdXur3C9sh6LFk8yuHo9dbx5g6My";

	private static final Auth auth = Auth.create(access, secret_key);
	
	private static //创建上传对象
	UploadManager uploadManager = new UploadManager();
	
	public static String getToken(){
		return auth.uploadToken("meipin");
	}
	
	public static void upload(String fileName) throws LMException{
		try {
			//调用put方法上传
//			Response res = uploadManager.put("./"+fileName, fileName, getToken());
			uploadManager.put("./"+fileName, fileName, getToken());
			//打印返回的信息
//			System.out.println(res.bodyString()); 
		} catch (QiniuException e) {
			Response r = e.response;
			if(!r.isOK()){
				throw new LMException(100041);
			}
	      }       
	  }
//	
//	public static void main(String[] args) throws LMException {
//		String base = "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAXnElEQVR4Xu2defxf05nH30I0pCpmmBqlW9AmxUxt9appq2ZedCzplDZEEvuWINQ0aIOiKJoOEkkY7ah9V4ppmVESZswgxlJRr0lrndEFk0oiJCnzen75/eLnl++95znnnnO373P+vc95zudZPvece+5ZVsNKTA8sA9aIqbBCXc8BH6uw/Vo0vVotUDQbxAvAJs02wYl+FjDRKdVCASNIWFA/DDwfVrXxtdYBFjXeCqUBRhClo3rFbgW+7FeltdJ7Ane01rpew4wguggvB1bXiRaW2gX4l4JaDgZ+WFCHtvpi4P1a4abJGUHyI/Yq8CeJgirfLS8l0p2ldnPgmURttvKj3gjSOVseBT4dMZHeBGTsLj1RnYq8+RdGBnQ0MCOyzsrUGUHe6/q9gZsiRaOJifJt4LRI9suQ9O1IuipTYwR51/XvRIjC6RETLAKcQiouBQ4tpGFF5UbnWKPBRwieqHi9d/hTRF3b/Vj05TEJmF7EwVXVbX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K5CYII=";
//		QiNiuController q = new QiNiuController();
//		String fileName = q.getFileName()+".jpg";
//		System.out.println(fileName);
//		if(!q.Base64ImgDown(base,"./"+fileName)){
//			throw new LMException(100040);
//		}
//		LMQiNiuAPI.upload(fileName);
//		File f = new File("./"+fileName);
//		if(f.exists()){
//			f.delete();
//		}
//	}
//	
}
